package com.qg.wcsopcuaqj.view.controller;


import com.qg.wcsopcuaqj.business.entity.TWcsTask;
import com.qg.wcsopcuaqj.business.entity.TWcsTaskLog;
import com.qg.wcsopcuaqj.business.service.ITWcsTaskLogService;
import com.qg.wcsopcuaqj.business.service.ITWcsTaskService;
import com.qg.wcsopcuaqj.common.utils.CommonFunction;
import com.qg.wcsopcuaqj.dispatch.constant.QGSConstant;
import com.qg.wcsopcuaqj.dispatch.entity.RGV1Entity;
import com.qg.wcsopcuaqj.dispatch.service.DDJService;
import com.qg.wcsopcuaqj.enums.furnace.FurnancePlc2WcsVarEnum;
import com.qg.wcsopcuaqj.enums.rgv1.RGV1Plc2WcsVarEnum;
import com.qg.wcsopcuaqj.enums.rgv1.RGV1Wcs2PlcVarEnum;
import com.qg.wcsopcuaqj.enums.rgv2.RGV2Plc2WcsVarEnum;
import com.qg.wcsopcuaqj.enums.yeyatai.yeya1.YY1Plc2WcsVarEnum;
import com.qg.wcsopcuaqj.enums.yeyatai.yeya1.YY1Wcs2PlcVarEnum;
import com.qg.wcsopcuaqj.enums.yeyatai.yeya2.YY2Plc2WcsVarEnum;
import com.qg.wcsopcuaqj.enums.yeyatai.yeya2.YY2Wcs2PlcVarEnum;
import com.qg.wcsopcuaqj.enums.yeyatai.yeya3.YY3Plc2WcsVarEnum;
import com.qg.wcsopcuaqj.enums.yeyatai.yeya3.YY3Wcs2PlcVarEnum;
import com.qg.wcsopcuaqj.enums.yeyatai.yeya4.YY4Plc2WcsVarEnum;
import com.qg.wcsopcuaqj.enums.yeyatai.yeya4.YY4Wcs2PlcVarEnum;
import com.qg.wcsopcuaqj.opcua.controller.R;
import com.qg.wcsopcuaqj.opcua.selfunion.Enum.PLCType;
import com.qg.wcsopcuaqj.opcua.selfunion.UAService;
import com.qg.wcsopcuaqj.view.entity.RGVViewer;
import com.qg.wcsopcuaqj.view.entity.ViewInfomation;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @Author: 蔡翔
 * @Date: 2019/10/12 15:15
 * @Version 1.0
 */
@RestController
@RequestMapping("/view")
public class ViewController {


    @Autowired
    UAService uaService;



    //获取可视化所需的 所有信息 ,, 前端会定期轮询这个接口
    @PostMapping("/getAllInfo")
    public ViewInfomation getAllInfo() throws Exception {
        ViewInfomation viewInfomation = new ViewInfomation();
//        //读取plc中 rgv1 的状态值
//        RGVViewer rgvViewer1 = new RGVViewer();
//        rgvViewer1.setIsFree(Boolean.parseBoolean(getValue(RGV1Plc2WcsVarEnum.Free)));
//        rgvViewer1.setCommuniStatus(Boolean.parseBoolean(getValue(RGV1Plc2WcsVarEnum.RGV1)));
//        rgvViewer1.setTaskNumber(Integer.parseInt(getValue(RGV1Plc2WcsVarEnum.TaskNo)));
//        viewInfomation.setRgv1(rgvViewer1);
//
//        //读取plc中 rgv2 的状态值
//        RGVViewer rgvViewer2 = new RGVViewer();
//        rgvViewer2.setIsFree(Boolean.parseBoolean(getValue(RGV2Plc2WcsVarEnum.Free)));
//        rgvViewer2.setCommuniStatus(Boolean.parseBoolean(getValue(RGV2Plc2WcsVarEnum.RGV2)));
//        rgvViewer2.setTaskNumber(Integer.parseInt(getValue(RGV2Plc2WcsVarEnum.TaskNo)));
//        viewInfomation.setRgv2(rgvViewer2);


        //读取plc中 rgv1 的状态值
        RGVViewer rgvViewer1 = new RGVViewer();
        rgvViewer1.setIsFree(true);
        rgvViewer1.setCommuniStatus(true);
        rgvViewer1.setTaskNumber(1);
        viewInfomation.setRgv1(rgvViewer1);

        //读取plc中 rgv2 的状态值
        RGVViewer rgvViewer2 = new RGVViewer();
        rgvViewer2.setIsFree(false);
        rgvViewer2.setCommuniStatus(false);
        rgvViewer2.setTaskNumber(1);
        viewInfomation.setRgv2(rgvViewer2);


        //读取多用炉信息


        //读取氮化炉信息

        //读取回火炉信息

        //读取清洗机信息


        return viewInfomation;
    }

    private String getValue(RGV1Plc2WcsVarEnum var) throws Exception {
        return uaService.getValue(var.getNamespace(), var.getIdentity(), QGSConstant.plcName).getValue().getValue().toString();
    }
    private String getValue(RGV2Plc2WcsVarEnum var) throws Exception {
        return uaService.getValue(var.getNamespace(), var.getIdentity(), QGSConstant.plcName).getValue().getValue().toString();
    }
    private String getValue(FurnancePlc2WcsVarEnum var) throws Exception {
        return uaService.getValue(var.getNamespace(), var.getIdentity(), QGSConstant.plcName).getValue().getValue().toString();
    }
}
